package org.example.app.model;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Generated;
import lombok.NoArgsConstructor;
import org.example.app.web.vm.BookKeepVm;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

@Data
@Entity
@Table(name = "book_keep")
@NoArgsConstructor
@AllArgsConstructor
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class BookKeep implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(name = "add_time")
    private LocalDateTime addTime = LocalDateTime.now();

    @Column(name = "update_time")
    private LocalDateTime updateTime = LocalDateTime.now();

    @Column(name = "book_keep_date")
    private LocalDate bookKeepDate = LocalDate.now(); //记账时间

    @Column
    private Integer type;//类型，0：支出 1：收入

    @Column
    private String category;//分类

    @Column
    private BigDecimal price;//金额

    @Column
    private String remark;//备注


    // 添加外键关联
    @ManyToOne
    @JoinColumn(name = "user_id") // 外键列名
    private User user; // 与User实体关联

    public BookKeep(BookKeepVm bookKeepVm,User user) {
        this.bookKeepDate = bookKeepVm.getBookKeepDate();
        this.type = bookKeepVm.getType();
        this.category = bookKeepVm.getCategory();
        this.price = bookKeepVm.getPrice();
        this.remark = bookKeepVm.getRemark();
        this.user = user;
    }

    public BookKeep(BookKeep bookKeep) {
    }
}